package com.orange.eduservice.controller;


import com.orange.commonutils.result.Result;
import com.orange.eduservice.entity.vo.OneSubject;
import com.orange.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author orange
 * @since 2021-12-17
 */
@RestController
@RequestMapping("/eduService/edu-subject")
@CrossOrigin //解决跨域问题
@Api(tags ="课程分类管理")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    //添加课程分类
    //获取上传过来的文件，把文件内容读取出来
    @ApiOperation("上传课程分类excel文件")
    @PostMapping("/addSubject")
    public Result addSubject(@ApiParam("excel文件") MultipartFile file){
        //获取上传的excel文件 MultipartFile
        eduSubjectService.saveSubject(file,eduSubjectService);
        //判断返回集合是否为空
        return Result.ok();
    }

    @ApiOperation("获取树形课程分类列表")
    @GetMapping("/getAllSubject")
    public Result getAllSubject(){
        List<OneSubject> list = eduSubjectService.getSubjects();
        return Result.ok().data("list", list);
    }
}

